//
//  NetworkTool.swift
//  LCYWeiBo
//
//  Created by 李长友 on 16/9/2.
//  Copyright © 2016年 app. All rights reserved.
//

import Alamofire

class NetworkTools {
    static let shareInstance = NetworkTools()
}

extension NetworkTools {
    
    // MARK: - 请求accessToken
    func loadAccessToken(code: String, response: Response<AnyObject, NSError> -> Void) {
        
        let params = ["client_id" : app_key,
                      "client_secret" : app_secret,
                      "grant_type" : "authorization_code",
                      "redirect_uri" : redirect_uri,
                      "code" : code]
        
        Alamofire.request(.POST, "https://api.weibo.com/oauth2/access_token", parameters: params).responseJSON(completionHandler: response)
    }

    //MARK: - 请求用户信息
    func loadUserInfo(access_token: String, uid: String, response: Response<AnyObject, NSError> -> Void) {
        
        let params = ["access_token" : access_token,
                      "uid" : uid]
        
        Alamofire.request(.GET, "https://api.weibo.com/2/users/show.json", parameters: params).responseJSON(completionHandler: response)
    }
    
    //MARK: - 请求首页微博
    func loadHomeStatuses(response: Response<AnyObject, NSError> -> Void) {
        
        let params = ["access_token" : (UserViewModel.shareInstance.user?.access_token)!]
        
        Alamofire.request(.GET, "https://api.weibo.com/2/statuses/home_timeline.json", parameters: params).responseJSON(completionHandler: response)
    }
}





















